<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>Title</title>
</head>
<body>
<div>aaa</div>
<div class="header">bbb</div>
<div id="ab">ccc</div>

<script>
(function (global) {

	function jQuery(selector) {
	    return new jQuery.fn.init(selector)
	}

	jQuery.fn = jQuery.prototype = {
		constructor: jQuery,
	    init:function(selector) {
			    const elements = document.querySelectorAll(selector);

			    for(let i=0;i<elements.length;i++){
				    this[i] =  elements[i];
			    }
			    this.length = elements.length;

		    },
	    css(name, val) {
		    for(let i=0;i<this.length;i++){
			    let element = this[i]
			    element.style[name] = val;
		    }
        }
	}

	jQuery.fn.init.prototype = jQuery.fn

	jQuery.fn.extend = jQuery.extend = function (...args) {
			//判断2种情况
			// $.extend({}) -->给$添加属性
			// $.fn.extend({}) -->给$.fn添加属性

			// 参数个数>1，就是给第一个实参添加属性
			let target,source = []
				source = [...args]

			if(args.length === 1){
				target = this
			}else {
				// 参数个数>1
				target = args[0] //目标对晚服就是第一个实参
				source.splice(0,1) //源对象就是第二个及其后面的实参
			}
			// 后面拷贝过程都是一样的

			Object.assign(target,...source)

		    return target;
    }

	global.$ = global.jQuery = jQuery;

})(window)

	var obj = {name:'xxx',age:18}
	var obj3 = {gender:'女'}
	var p = {}
	$.extend(p,obj,obj3)
</script>
</body>
</html>